﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using QBWeb.Models;
using QBWeb.Models.QuestionFolder;

namespace QBWeb.Controllers
{
    /// <summary>
    /// 题目类型控制器类
    /// </summary>
    public class QuestTypeTbsController : Controller
    {
        private readonly QBDbContext db = new QBDbContext();

        /// <summary>
        /// GET: QuestTypeTbs
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View(db.QuestTypeTbs.ToList());
        }

        /// <summary>
        /// GET: QuestTypeTbs/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            QuestTypeTb questTypeTb = db.QuestTypeTbs.Find(id);
            if (questTypeTb == null)
            {
                return HttpNotFound();
            }
            return View(questTypeTb);
        }

        /// <summary>
        /// GET: QuestTypeTbs/Create
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            return View();
        }

        /// <summary>
        /// POST: QuestTypeTbs/Create
        /// </summary>
        /// <param name="questTypeTb"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,TypeName")] QuestTypeTb questTypeTb)
        {
            if (ModelState.IsValid)
            {
                db.QuestTypeTbs.Add(questTypeTb);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(questTypeTb);
        }

        /// <summary>
        /// GET: QuestTypeTbs/Edit/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            QuestTypeTb questTypeTb = db.QuestTypeTbs.Find(id);
            if (questTypeTb == null)
            {
                return HttpNotFound();
            }
            return View(questTypeTb);
        }

        /// <summary>
        /// POST: QuestTypeTbs/Edit/5
        /// </summary>
        /// <param name="questTypeTb"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "ID,TypeName")] QuestTypeTb questTypeTb)
        {
            if (ModelState.IsValid)
            {
                db.Entry(questTypeTb).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(questTypeTb);
        }

        /// <summary>
        /// GET: QuestTypeTbs/Delete/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            QuestTypeTb questTypeTb = db.QuestTypeTbs.Find(id);
            if (questTypeTb == null)
            {
                return HttpNotFound();
            }
            return View(questTypeTb);
        }

        /// <summary>
        /// POST: QuestTypeTbs/Delete/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            QuestTypeTb questTypeTb = db.QuestTypeTbs.Find(id);
            db.QuestTypeTbs.Remove(questTypeTb);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
